/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package es.us.mwm.entities;

import java.io.Serializable;
import java.util.Date;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 * Clase para la gestión de la tabla Alerts de la base de datos. Entity CLASE GENERADA AUTOMATICAMENTE. NO MODIFICADA
 *
 * @author y0rg
 */
@Entity
@Table(name = "USERS")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Users.findAll", query = "SELECT u FROM Users u"),
    @NamedQuery(name = "Users.findByUse", query = "SELECT u FROM Users u WHERE u.user = :user"),
    @NamedQuery(name = "Users.findByPassword", query = "SELECT u FROM Users u WHERE u.password = :password"),
    @NamedQuery(name = "Users.findByEmail", query = "SELECT u FROM Users u WHERE u.email = :email"),
    @NamedQuery(name = "Users.findByLastconnection", query = "SELECT u FROM Users u WHERE u.lastConnection = :lastconnection"),
    @NamedQuery(name = "Users.findByStatus", query = "SELECT u FROM Users u WHERE u.status = :status"),
    @NamedQuery(name = "Users.findBySuperadmin", query = "SELECT u FROM Users u WHERE u.superadmin = :superadmin"),
    @NamedQuery(name = "Users.logIn", query = "SELECT u FROM Users u WHERE u.user = :user AND u.password = :pass AND u.status !='Inactive'")
})
public class Users implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 10)
    @Column(name = "USE")
    private String user;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 10)
    @Column(name = "PASSWORD")
    private String password;
    @Pattern(regexp = "[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?", message = "Incorrect email format")//if the field contains email address consider using this annotation to enforce field validation
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 50)
    @Column(name = "EMAIL")
    private String email;
    @Basic(optional = false)
    @Column(name = "LASTCONNECTION")
    @Temporal(TemporalType.TIMESTAMP)
    private Date lastConnection;
    @Size(max = 10)
    @Column(name = "STATUS")
    private String status;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 1)
    @Column(name = "SUPERADMIN")
    private String superadmin;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "user")
    private List<Alerts> alertsList;

    /**
     * Constructor sin parametros.
     */
    public Users() {
    }

    /**
     * Constructor de clase a partir de un usuario
     *
     * @param user usuario
     */
    public Users(String user) {
        this.user = user;
    }

    /**
     * Constructor con todos los parametros
     *
     * @param user usuario
     * @param password password
     * @param email email
     * @param lastconnection fecha ultima conexion
     * @param superadmin es superadministrador?
     */
    public Users(String user, String password, String email, Date lastconnection, String superadmin) {
        this.user = user;
        this.password = password;
        this.email = email;
        this.lastConnection = lastconnection;
        this.superadmin = superadmin;
    }

    /**
     * Metodo de acceso a atributo
     *
     * @return usuario
     */
    public String getUser() {
        return user;
    }

    /**
     * Metodo de acceso a atributo
     *
     * @param user usuario
     */
    public void setUser(String user) {
        this.user = user;
    }

    /**
     * Metodo de acceso a atributo
     *
     * @return password
     */
    public String getPassword() {
        return password;
    }

    /**
     * Metodo de acceso a atributo
     *
     * @param password password
     */
    public void setPassword(String password) {
        this.password = password;
    }

    /**
     * Metodo de acceso a atributo
     *
     * @return email
     */
    public String getEmail() {
        return email;
    }

    /**
     * Metodo de acceso a atributo
     *
     * @param email email
     */
    public void setEmail(String email) {
        this.email = email;
    }

    /**
     * Metodo de acceso a atributo
     *
     * @return fecha ultima conexion
     */
    public Date getLastConnection() {
        return lastConnection;
    }

    /**
     * Metodo de acceso a atributo
     *
     * @param lastconnection fecha ultima conexion
     */
    public void setLastConnection(Date lastconnection) {
        this.lastConnection = lastconnection;
    }

    /**
     * Metodo de acceso a atributo
     *
     * @return estado: activo, inactivo, conectado
     */
    public String getStatus() {
        return status;
    }

    /**
     * Metodo de acceso a atributo
     *
     * @param status estado: activo, inactivo, conectado
     */
    public void setStatus(String status) {
        this.status = status;
    }

    /**
     * Metodo de acceso a atributo
     *
     * @return es superadmin? Y/N
     */
    public String getSuperadmin() {
        return superadmin;
    }

    /**
     * Metodo de acceso a atributo
     *
     * @param superadmin es superadmin? Y/N
     */
    public void setSuperadmin(String superadmin) {
        this.superadmin = superadmin;
    }

    /**
     * Metodo de acceso a atributo
     *
     * @return lista de alertas gestionadas por el usuario
     */
    @XmlTransient
    public List<Alerts> getAlertsList() {
        return alertsList;
    }

    /**
     * Metodo de acceso a atributo
     *
     * @param alertsList lista de alertas gestionadas por el usuario
     */
    public void setAlertsList(List<Alerts> alertsList) {
        this.alertsList = alertsList;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (user != null ? user.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Users)) {
            return false;
        }
        Users other = (Users) object;
        if ((this.user == null && other.user != null) || (this.user != null && !this.user.equals(other.user))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "Users{" + "user=" + user + ", password=" + password + ", email=" + email + ", lastconnection=" + lastConnection
                + ", status=" + status + ", superadmin=" + superadmin + ", alertsList=" + alertsList + '}';
    }

}
